home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 June: Reference Library / Dev.CD Jun 96 RL / Dev.CD Jun 96 RL.toast / Technical Documentation / develop / develop Issue 24 / develop Issue 24 code / Scriptable Database 1.0a15 / Application / AbstractDocument.cp next >
Encoding:
Text File  |  1996-02-19  |  7.4 KB  |  234 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        AbstractDocument.c
  3.  
  4.     Contains:    Abstract base class for documents
  5.  
  6.     Written by:    Greg Anderson
  7.  
  8.     Copyright:    © 1993 by Greg Anderson, all rights reserved.
  9.  
  10.                  3/31/93    ga        
  11.  
  12.     To Do:
  13. */
  14.  
  15. #include "AbstractDocument.h"
  16.  
  17. #include <AERegistry.h>
  18.  
  19. #include "Exceptions.h"
  20.  
  21. TAbstractDocument* gOpenDocumentList = nil;
  22.  
  23. #define clAbstractDocument 42
  24.  
  25. #pragma segment ObjectResident
  26. ImplementSmallClassData(TAbstractDocument, clAbstractDocument);
  27.  
  28.  
  29. //----------------------------------------------------------------------------------------
  30. // FirstOpenDocument: 
  31. //----------------------------------------------------------------------------------------
  32. TAbstractDocument* FirstOpenDocument()
  33. {
  34.     return gOpenDocumentList;
  35. } // FirstOpenDocument 
  36.  
  37. //----------------------------------------------------------------------------------------
  38. // LastOpenDocument: 
  39. //----------------------------------------------------------------------------------------
  40. TAbstractDocument* LastOpenDocument()
  41. {
  42.     TAbstractDocument* doc = gOpenDocumentList;
  43.     TAbstractDocument* nextDoc = doc;
  44.     
  45.     while(nextDoc != nil)
  46.     {
  47.         doc = nextDoc;
  48.         nextDoc = doc->NextDocument();
  49.     }
  50.     
  51.     return doc;
  52. } // LastOpenDocument 
  53.  
  54.  
  55.  
  56. //========================================================================================
  57. // CLASS TAbstractDocument
  58. //========================================================================================
  59.  
  60.  
  61. //----------------------------------------------------------------------------------------
  62. // TAbstractDocument::TAbstractDocument: 
  63. //----------------------------------------------------------------------------------------
  64. TAbstractDocument::TAbstractDocument()
  65. {
  66.     fCloseRequested = false;
  67.     this->PushOnDocumentList();
  68. }
  69.  
  70. //----------------------------------------------------------------------------------------
  71. // TAbstractDocument::~TAbstractDocument: 
  72. //----------------------------------------------------------------------------------------
  73. TAbstractDocument::~TAbstractDocument()
  74. {
  75.     this->RemoveFromDocumentList();
  76. }
  77.  
  78. //----------------------------------------------------------------------------------------
  79. // TAbstractDocument::RemoveFromDocumentList: 
  80. //----------------------------------------------------------------------------------------
  81. void TAbstractDocument::RemoveFromDocumentList()
  82. {
  83.     //
  84.     // Remove ourselves from the linked list
  85.     //
  86.     if(fNextDocument != nil)
  87.         fNextDocument->fPreviousDocument = fPreviousDocument;
  88.     if(fPreviousDocument != nil)
  89.         fPreviousDocument->fNextDocument = fNextDocument;
  90.     //
  91.     // If we are on the head of the list, then fix up the head pointer
  92.     //    
  93.     else // (fPreviousDocument == nil)
  94.     {
  95.         if(gOpenDocumentList == this)
  96.             gOpenDocumentList = fNextDocument;
  97.     }
  98.     
  99.     //
  100.     // Clear our links
  101.     //
  102.     fNextDocument = nil;
  103.     fPreviousDocument = nil;
  104. } // TAbstractDocument::RemoveFromDocumentList 
  105.  
  106. //----------------------------------------------------------------------------------------
  107. // TAbstractDocument::IAbstractDocument: 
  108. //----------------------------------------------------------------------------------------
  109. void TAbstractDocument::IAbstractDocument()
  110. {
  111.     //
  112.     // Nothing to do here
  113.     //
  114. } // TAbstractDocument::IAbstractDocument 
  115.  
  116. //----------------------------------------------------------------------------------------
  117. // TAbstractDocument::Clone: 
  118. //
  119. // Derived classes should call 'new' themselves, then clone the fields of the new object
  120. //----------------------------------------------------------------------------------------
  121. TAbstractScriptableObject* TAbstractDocument::Clone()
  122. {
  123.     TAbstractDocument* clonedDocument = (TAbstractDocument*)TAbstractScriptableObject::Clone();
  124.     
  125.     //
  126.     // Overwrite our old previous and next links
  127.     //
  128.     clonedDocument->PushOnDocumentList();
  129.     
  130.     return clonedDocument;
  131. } // TAbstractDocument::Clone 
  132.  
  133. //----------------------------------------------------------------------------------------
  134. // TAbstractDocument::PushOnDocumentList: 
  135. //----------------------------------------------------------------------------------------
  136. void TAbstractDocument::PushOnDocumentList()
  137. {
  138.     //
  139.     // Push ourselves on the list of open documents
  140.     //
  141.     if(gOpenDocumentList)
  142.         gOpenDocumentList->fPreviousDocument = this;
  143.     fNextDocument = gOpenDocumentList;
  144.     gOpenDocumentList = this;
  145.     
  146.     //
  147.     // Clear our 'previous' list
  148.     //
  149.     fPreviousDocument = nil;
  150. } // TAbstractDocument::PushOnDocumentList 
  151.  
  152. #if 0
  153. //----------------------------------------------------------------------------------------
  154. // TAbstractDocument::operator=: 
  155. //----------------------------------------------------------------------------------------
  156. TAbstractDocument& TAbstractDocument::operator=(const TAbstractDocument& rhs)
  157. {
  158.     //
  159.     // Remember what our forward and backward links used to be
  160.     //
  161.     TAbstractDocument* nextDocument = fNextDocument;
  162.     TAbstractDocument* previousDocument = fPreviousDocument;
  163.  
  164.     //
  165.     // Call the inherited operator=, which copies all of the
  166.     // fields from 'rhs' into this object
  167.     //
  168.     TAbstractScriptableObject::operator=(rhs);
  169.     
  170.     //
  171.     // Now put our forward and backward links back the way they were
  172.     // If this assignment is being done as a result of a clone, then
  173.     // TAbstractDocument::Clone will fix up the next and previous links.
  174.     //
  175.     fNextDocument = nextDocument;
  176.     fPreviousDocument = previousDocument;
  177.     
  178.     return *this;
  179. } // TAbstractDocument::operator= 
  180. #endif
  181.  
  182. //----------------------------------------------------------------------------------------
  183. // TAbstractDocument::DocumentFSSpecification
  184. //
  185. // Return the TFSSpecification for the file this document is saved in, if any.
  186. //----------------------------------------------------------------------------------------
  187. Boolean TAbstractDocument::DocumentFSSpecification(TFSSpecification&) const
  188. {
  189.     return false;
  190. }
  191.  
  192. //----------------------------------------------------------------------------------------
  193. // TAbstractDocument::ObjectClass: 
  194. //----------------------------------------------------------------------------------------
  195. DescType TAbstractDocument::ObjectClass(const TAETransaction&, Boolean /*recordedClass*/)
  196. {
  197.     return cDocument;
  198. } // TAbstractDocument::ObjectClass 
  199.  
  200. //----------------------------------------------------------------------------------------
  201. // TAbstractDocument::DerivedFromOSLClass: 
  202. //----------------------------------------------------------------------------------------
  203. Boolean TAbstractDocument::DerivedFromOSLClass(const TAETransaction& t, DescType objectClass)
  204. {
  205.     return ((objectClass == cDocument) || TAbstractScriptableObject::DerivedFromOSLClass(t, objectClass));
  206. } // TAbstractDocument::DerivedFromOSLClass 
  207.  
  208. //================================================================================
  209. // Class TDocumentLoop
  210. //================================================================================
  211.  
  212. //----------------------------------------------------------------------------------------
  213. // TDocumentLoop::~TDocumentLoop
  214. //----------------------------------------------------------------------------------------
  215. TDocumentLoop::~TDocumentLoop()
  216. {
  217. }// TDocumentLoop::~TDocumentLoop
  218.  
  219. //----------------------------------------------------------------------------------------
  220. // TDocumentLoop::RemoveCurrentDocument
  221. //----------------------------------------------------------------------------------------
  222. TAbstractDocument* TDocumentLoop::RemoveCurrentDocument(const TAETransaction& t)
  223. {
  224.     TAbstractDocument* removee = this->CurrentDocument();
  225.     if(removee)
  226.     {
  227.         this->Next(t);
  228.         removee->RemoveFromDocumentList();
  229.     }
  230.     fRemovedCurrent = true;
  231.     return removee;
  232. } // TDocumentLoop::RemoveCurrentDocument
  233.  
  234.